<?php
//=======================================
// !! GYSN RELEASE - DO NOT REMOVE  !!
// !! DeZend by: syairx             !!
// !! Debug by: syairx & str/GYSN   !!
// !! Nullify by: str/GYSN & syairx !!
// !! GYSN RELEASE - DO NOT REMOVE  !!
//=======================================

if ( !defined( "INSWIFT" ) )
{
    trigger_error( "Unable to process ".$PHP_SELF, E_USER_ERROR );
}

if ( !$staffauth->isAdmin( ) )
{
    trigger_error( "You do not have permission to access ".$PHP_SELF, E_USER_ERROR );
}

$template->loadLanguageSection( "diagnostics" );
require_once( "./includes/functions_html.php" );

if ( $eventaction == "phpinfo" )
{
    $interface->adminHeader( $_SWIFT["language"]["diagnostics"]." > ".$_SWIFT["language"]["phpinfo"] );

    $interface->adminNavBar( $_SWIFT["language"]["phpinfo"], $_SWIFT["language"]["desc_phpinfo"], 12 );

    ob_start( );

    phpinfo( INFO_GENERAL | INFO_CONFIGURATION );

    $valInfo .= ob_get_contents( );
    ob_end_clean( );

    echo str_replace( "phpinfo()", "", str_replace( 'width="600"', 'width="100%"', strip_tags( $valInfo, "<tr><td><table><h1><h2><img>" ) ) );
    $interface->adminFooter( );
}
else if ( $eventaction == "mysqlinfo" )
{
    $interface->adminHeader( $_SWIFT["language"]["diagnostics"]." > ".$_SWIFT["language"]["mysqlinfo"] );

    $interface->adminNavBar( $_SWIFT["language"]["mysqlinfo"], $_SWIFT["language"]["desc_mysqlinfo"], 12 );

    printMainTableHeader( $_SWIFT["language"]["mysqlinfo"] );
    $colarray[0]["align"] = "left";
    $colarray[0]["valign"] = "top";
    $colarray[0]["nowrap"] = true;
    $colarray[0]["value"] = $_SWIFT["language"]["variable"];
    $colarray[1]["align"] = "left";
    $colarray[1]["valign"] = "top";
    $colarray[1]["value"] = $_SWIFT["language"]["value"];
    printDataRow( $colarray, "tabletitlerow" );

    $dbCore->query( "SHOW VARIABLES;" );
    while ( $dbCore->nextRecord( ) )
    {
        printDefaultRow( $dbCore->Record["Variable_name"], $dbCore->Record["Value"] );
    }

    printMainTableFooter( );

    $interface->adminFooter( );
}
else if ( $eventaction == "cacheinfo" )
{
    if ( $_GET["do"] == "view" )
    {
        $cache = $registry->getKey( $_GET["cache"] );
        $cachearray = unserialize( $cache );

        ob_start( );
        print_r( $cachearray );
        $cachecontents = ob_get_contents( );
        ob_end_clean( );

        $template->assign( "documenttitle", $_SWIFT["language"]["cacheinfo"] );
        echo $template->displayTemplate( "header.tpl" );
        echo "<span class='smalltext'>".nl2br( str_replace( " ", "&nbsp;", htmlspecialchars( $cachecontents ) ) )."</span>";
        echo $template->displayTemplate( "footer.tpl" );
    }
    else
    {
    $interface->adminHeader( $_SWIFT["language"]["diagnostics"]." > ".$_SWIFT["language"]["cacheinfo"] );

    $interface->adminNavBar( $_SWIFT["language"]["cacheinfo"], $_SWIFT["language"]["desc_cacheinfo"], 12 );

    printMainTableHeader( $_SWIFT["language"]["cacheinfo"] );

    $colarray[0]["align"] = "left";
    $colarray[0]["nowrap"] = true;
    $colarray[0]["value"] = $_SWIFT["language"]["cachetitle"];
    $colarray[1]["width"] = "200";
    $colarray[1]["value"] = $_SWIFT["language"]["size"];
    $colarray[2]["width"] = "150";
    $colarray[2]["value"] = $_SWIFT["language"]["options"];

    printDataRow( $colarray, "tabletitlerow" );

    $dbCore->query( "SELECT * FROM `".TABLE_PREFIX."registry` ORDER BY `dateline` ASC;" );
    while ( $dbCore->nextRecord( ) )
    {
        $colarray = array( );
        $colarray[0]["align"] = "left";
        $colarray[0]["valign"] = "middle";
        $colarray[0]["value"] = '<a href="javascript:popupInfoWindow(\'index.php?_m=core&_a=cacheinfo&do=view&cache='.urlencode( $dbCore->Record["vkey"] ).'\');">'.$dbCore->Record["vkey"].'</a>';
        $colarray[1]["align"] = "center";
        $colarray[1]["valign"] = "middle";
        $colarray[1]["value"] = formattedSize( $dbCore->Record["datasize"] );
        $colarray[2]["align"] = "center";
        $colarray[2]["valign"] = "middle";
        $colarray[2]["value"] = '<a href="javascript:popupInfoWindow(\'index.php?_m=core&_a=cacheinfo&do=view&cache='.urlencode( $dbCore->Record["vkey"] ).'\');"><img src="'.$_SWIFT["themepath"].'icon_view.gif" border="0">&nbsp;'.$_SWIFT["language"]["view"].'</a>';

        printDataRow( $colarray );
    }

    printMainTableFooter( );

    $interface->adminFooter( );
    }
}
else if ( $eventaction == "activesessions" )
{
    if ( $_GET["action"] == "kill" && !empty( $_GET["csessionid"] ) )
    {
        $dbCore->query( "DELETE FROM `".TABLE_PREFIX."sessions` WHERE `sessionid` = '".$dbCore->escape( $_GET["csessionid"] )."';" );
        $infomessage = $_SWIFT["language"]["sessiondelconfirm"];
    }

    $interface->adminHeader( $_SWIFT["language"]["diagnostics"]." > ".$_SWIFT["language"]["activesessions"], 1 );

    $interface->adminNavBar( $_SWIFT["language"]["activesessions"], $_SWIFT["language"]["desc_activesessions"], 12 );

    printInfoBox( $infomessage );
    printErrorBox( $errormessage );

    printMainTableHeader( $_SWIFT["language"]["sessionlist"] );

    $colarray[0]["align"] = "center";
    $colarray[0]["nowrap"] = true;
    $colarray[0]["value"] = $_SWIFT["language"]["ipaddress"];
    $colarray[0]["width"] = "120";
    $colarray[1]["width"] = "120";
    $colarray[1]["value"] = $_SWIFT["language"]["lastactivity"];
    $colarray[2]["width"] = "120";
    $colarray[2]["value"] = $_SWIFT["language"]["sessiontype"];
    $colarray[3]["value"] = $_SWIFT["language"]["useragent"];
    $colarray[4]["width"] = "120";
    $colarray[4]["value"] = $_SWIFT["language"]["options"];

    printDataRow( $colarray, "tabletitlerow" );

    $dbCore->query( "SELECT * FROM `".TABLE_PREFIX."sessions` ORDER BY `lastactivity` DESC;" );
    while ( $dbCore->nextRecord( ) )
    {
        $colarray = array( );
        $colarray[0]["align"] = "center";
        $colarray[0]["valign"] = "middle";
        $colarray[0]["value"] = htmlspecialchars( $dbCore->Record["ipaddress"] );

        $colarray[1]["align"] = "center";
        $colarray[1]["valign"] = "middle";
        $colarray[1]["value"] = strColorDate( DATENOW - $dbCore->Record["lastactivity"] );

        $sessionkey = "sess".$dbCore->Record["sessiontype"];
        $colarray[2]["align"] = "center";
        $colarray[2]["valign"] = "middle";
        $colarray[2]["value"] = $_SWIFT["language"][$sessionkey];

        $colarray[3]["align"] = "center";
        $colarray[3]["valign"] = "middle";
        $colarray[3]["value"] = htmlspecialchars( $dbCore->Record["useragent"] );

        $colarray[4]["align"] = "center";
        $colarray[4]["valign"] = "middle";
        $colarray[4]["value"] = '<a href="index.php?_m=core&_a=activesessions&action=kill&csessionid='.$dbCore->Record["sessionid"].'"><img src="'.$_SWIFT["themepath"].'icon_deletesmall.gif" border="0">&nbsp;'.$_SWIFT["language"]["killsession"].'</a>';

        printDataRow( $colarray );
    }

    printMainTableFooter( );
    $interface->adminFooter( );
}

?>